<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /**
         * promise状态的改变：
         * 
         * 1. pending --> fulfilled
         * 2. pending --> rejected
         * 
         * 不能从fulfilled --> rejected, 也不能从 rejected-->fulfilled，也不能从fulfilled-->pending,还不能从 rejected-->pending
         * 
         */
        let p = new Promise((resolve, reject)=>{
            reject('error');
            // 下面的改变无效
            resolve('ok');
        })
        console.log(p);
        // then 作用：给promise对象指定成功和失败的函数
        p.then(value=>{
            console.log('success value: ', value);
        }, reason=>{
            console.log('fail reason: ', reason);
        })
    </script>
</body>
</html>